package com.crocodileQ.controller;


import com.crocodileQ.common.AppException;
import com.crocodileQ.common.PageResult;
import com.crocodileQ.common.R;
import com.crocodileQ.constants.SystemConstants;
import com.crocodileQ.domain.VO.CommentVO;
import com.crocodileQ.domain.entity.Comment;
import com.crocodileQ.enums.AppExceptionMsgEnum;
import com.crocodileQ.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 查询文章评论
     * @param articleId
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/commentList")
    public R<PageResult<CommentVO>> commentList(Long articleId, Integer pageNum, Integer pageSize){
        //判断参数
        if(pageNum <= 0 || pageSize <= 0){
            throw new AppException(AppExceptionMsgEnum.WRONG_PAGE_PARAM);
        }

        return commentService.commentList(SystemConstants.ARTICLE_COMMENT,articleId,pageNum,pageSize);
    }

    @GetMapping("/linkCommentList")
    public R<PageResult<CommentVO>> linkCommentList( Integer pageNum, Integer pageSize){
        //判断参数
        if(pageNum <= 0 || pageSize <= 0){
            throw new AppException(AppExceptionMsgEnum.WRONG_PAGE_PARAM);
        }

        return commentService.commentList(SystemConstants.LINK_COMMENT, null,pageNum,pageSize);
    }

    /**
     * 发送评论
     */
    @PostMapping
    public R addComment(@RequestBody Comment comment){

       return commentService.addComment(comment);
    }
}
